<template>
  <div>
    <h1>sse请求</h1>
    <el-button @click="sendRequest">发送请求</el-button>
  </div>
</template>

<script setup>
import { sseRequest } from '@/api/sse';

const sendRequest = async () => {
  try {
    fetch('http://10.21.4.212:9000/v1/sse/chat', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ msg: '你好' }),
    }).then(response => {
      const decoder = new TextDecoder('utf-8')
      const reader = response.body?.getReader()
      reader?.read().then((result) => {
        console.log(result, 'result>>>>>>');
        console.log(decoder.decode(result.value, { stream: true }))
      })
    })
  } catch (err) {
    console.log(err, 'err>>>>>>');
  }
};
</script>